<template>
  <!-- v-if="signalsRadio1.brandsLiss.length > 0" -->
  <div class="vendor_box" v-loading="signalsRadio1.loading" element-loading-text="加载中...">
    <!--  -->
    <Totalarticles v-if="signalsRadio1.title.title != ''" />
    <div style=" min-height: 200px" v-if="signalsRadio1.total > 0">
      <div class="vendor" v-for="item in signalsRadio1.brandsLiss">
        <div style="display: flex; align-items: center; margin-bottom: 10px">
          <img style="width: 16px; height: 16px" src="@/assets/img/pinpai.png" alt="" />
          <div class="vendor_h">{{ item.key }}</div>
        </div>
        <div style="flex: 1">
          <div class="vendor_cont">
            <div class="vendor_cont_one">
              <div style="text-align: left" class="vendor_cont_s">产品</div>
              <div class="morearr">
                <div style="display: flex; margin-top: 5px">
                  <span v-for="ele in item.field1Values.buckets.slice(0, 1)" style="margin-right: 5px"
                    @click="chanpinClick(ele.key)">{{ ele.key
                    }}</span>
                  <div v-if="item.field1Values.buckets.length > 2" class="more"
                    @click="moreGd(item.field1Values.buckets)">
                    更多
                  </div>
                </div>
              </div>
            </div>
            <div class="vendor_cont_one" @click="">
              <div class="vendor_cont_s">中标次数</div>
              <div style="color: #a9b1be">
                <span class="vendor_cont_size">{{ item.zb_num.value }}</span>次
              </div>
            </div>
            <div class="vendor_cont_one">
              <div class="vendor_cont_s">采购商数量</div>
              <div style="color: #a9b1be">
                <span class="vendor_cont_size">{{ item.caigou_num.value }}</span>家
              </div>
            </div>
            <div class="vendor_cont_one">
              <div class="vendor_cont_s">代理商数量</div>
              <div style="color: #a9b1be">
                <span class="vendor_cont_size">{{ item.daili_num.value }}</span>家
              </div>
            </div>
          </div>
          <div class="omission">
            <span style="color: #a9b1be">最新项目：</span>
            <span @click="zunxinxiangmu(item.top_score_hits.hits.hits[0]._source.nid)">{{
              item.top_score_hits.hits.hits[0]._source.title
            }}</span>
            <span style="margin-left: 15px">{{
              timestamp(item.top_score_hits.hits.hits[0]._source.release_time)
            }}</span>
          </div>
        </div>
      </div>
      <el-dialog v-model="dialogVisible" title="产品列表" width="30%" :before-close="handleClose">
        <div class="infordisplay">
          <span class="cate_label" v-for="item in boxes" @click="chanpinClick(item.key)">{{ item.key }}</span>
        </div>
      </el-dialog>
    </div>
    <Pagination ref="pagination" v-if="bx_center !== 1" />
    <!-- {{ bx_center }} -->
    <Vips v-if="signalsRadio1.brandsLiss.length > 0 && bx_center == 1" />
  </div>
  <div v-if="signalsRadio1.brandsLiss.length == 0" style="background-color: white; margin: 15px 0">
    <el-empty description="暂无数据" />
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import Totalarticles from "../totalarticles/index.vue";
import Pagination from "@/components/pagination/index.vue";
import Vips from "@/components/vipts/index.vue";
import { search_read } from "@/Api/shoop/index.js";
import { useRadio1Store } from "@/pain/search/search";
import { useCounterStore } from "@/pain/login/login";
const useRouters = useCounterStore();
// import { getbrand_zb } from "@/Api/shoop/index";
import { timestamp } from "@/utils/index";
import { useRouter } from "vue-router";
const router = useRouter();
import { userInfo } from '@/Api/api.js'
import CryptoJS from "crypto-js";
const key = CryptoJS.enc.Utf8.parse("ysh425ptjhcpo781"); //十六位十六进制数作为密钥偏移量
const iv = CryptoJS.enc.Utf8.parse("53c5a64c6be84e97"); //十六位十六进制数作为密钥偏移量
const token = localStorage.getItem("token");
//解密
function decrypt(text) {
  var result = CryptoJS.AES.decrypt(text, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return result.toString(CryptoJS.enc.Utf8);
}
const bx_center = ref(0)
const ids = ref()
if (token) {
  userInfo().then(rex => {
    ids.value = rex.data.data.level_id
    search_read().then((res) => {
      if (res.data.data.pp_center.indexOf(ids.value.toString()) == '-1') {
        bx_center.value = 1
      } else {
        bx_center.value = 0
      }
    });
  })
} else {
  ids.value = 0
}



const signalsRadio1 = useRadio1Store();
const dialogVisible = ref(false);
let boxes = ref([]);
const handleClose = (done) => {
  done();
};
const moreGd = (gd) => {
  dialogVisible.value = true;
  boxes.value = gd;
};

// const pinpaixq = (data) => {
//     if (!localStorage.getItem("token")) {
//         return (useRouters.uselogin = true);
//     }
//     if (signalsRadio1.routerPush == 'search') {
//         const href = router.resolve({
//             path: "/disposition",
//             query: {
//                 id: signalsRadio1.id,
//                 name: data.replace(/<[^>]+>/g, ""),
//             },
//         });
//         window.open(href.href, "_blank");
//     }
// }

const zunxinxiangmu = (nid) => {
  if (!localStorage.getItem("token")) {
    return (useRouters.uselogin = true);
  }
  if (signalsRadio1.routerPush == "search") {
    const href = router.resolve({
      path: `/searchInfo/${nid}`,
    });
    window.open(href.href, "_blank");
  }
};

const chanpinClick = (key) => {
  if (!localStorage.getItem("token")) {
    return (useRouters.uselogin = true);
  }
  const href = router.resolve({
    path: '/productanalysis',
    query: {
      name: key
    }
  });
  window.open(href.href, "_blank");
}
// signalsRadio1.id = router.currentRoute.value.query.id
onMounted(() => {
  // signalsRadio1.getsearchs()
});
</script>

<style lang="scss" scoped>
.origin {
  padding: 5px 6px;
  border-radius: 4px;
  background-color: #fe8d03;
  color: #fff;
  margin-left: 10px;
  font-size: 14px;
}

.vendor_box {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  min-height: 500px;
  background-color: #fff;

  //
  .vendor {
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-bottom: 1px solid #eeeeee;
    cursor: pointer;

    &:hover {
      background-color: #eeeeee;
    }
  }

  .vendor_h {
    margin-left: 6px;
    font-size: 16px;
    color: #333333;
  }

  .vendor_cont {
    display: flex;

    .vendor_cont_one {
      padding: 6px 16px;
      margin-right: 16px;
      background-color: #eef1fc;
      border-radius: 8px;
      font-size: 14px;
      color: #74798c;

      .vendor_cont_s {
        margin-bottom: 6px;
        font-size: 14px;
        color: #a9b1be;
      }

      .morearr {
        display: flex;
        justify-content: space-between;
        margin-top: 5px;
        color: #000;

        .more {
          margin-left: 15px;
          color: #5473da;
        }
      }

      .vendor_cont_size {
        font-size: 18px;
        font-weight: 600;
        padding-right: 10px;
        color: #000;
      }
    }
  }

  .omission {
    width: 1090px;
    margin-top: 10px;
    font-size: 14px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

.infordisplay {
  display: flex;
  flex-wrap: wrap;
  max-height: 400px;
  overflow: auto;
  padding: 16px 24px;

  .cate_label {
    margin-right: 10px;
    margin-bottom: 8px;
    padding: 2px 5px;
    border-radius: 5px;
    font-size: 14px;
    background: #fce2e0;
    color: #f43107;
  }
}

::v-deep .el-dialog__title {
  font-size: 16px;
}

::v-deep .el-dialog__header {
  padding: 12px 24px 0;
}

::v-deep .el-dialog__body {
  height: 100%;
}
</style>
